package BackTrackingPackage2;

import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Lzm
 * @version 1.0
 */
public class subsets_ {
  List<Integer> list = new ArrayList<>();
  List<List<Integer>> result = new ArrayList<>();

  @Test
  public void subsetsTest(){
    int[] nums = new int[]{1,2,3};
    List<List<Integer>> res = subsets(nums);
    for (List<Integer> re : res) {
      System.out.println(re.toString());
    }
  }
  public List<List<Integer>> subsets(int[] nums) {
    backTracking(nums,0);
    return result;
  }

  public void backTracking(int[] nums,int startIndex){
    result.add(new ArrayList<>(list));
    for (int i = startIndex ; i < nums.length ; i++){
      list.add(nums[i]);
      backTracking(nums,i + 1);
      list.remove(list.size() - 1);
    }
  }
}
